/* 月统计数据
 * @Author: wujie 
 * @Date: 2018-06-12 11:06:22 
 * @Last Modified by: wujie
 * @Last Modified time: 2018-07-02 18:49:02
 */
import React,{ Component } from 'react'
import { Row } from 'antd'
import components from '@/components/index'
import { connect } from 'react-redux'
import actions from '@/actions/monthStatistics'
import util from '@/utils'

const { MonthSendStatiticsSearch, MonthSendStatiticsTable, Card } = components

class MonthStatistics extends Component {

  render(){

    const searchProps = util.pick(this.props,[
      'endTime',
      'startTime'
    ])

    const tableProps = util.pick(this.props, [
      'pageNum',
      'pageSize',
      'loading',
      'total',
      'data'
    ])

    const searchFunProps = util.pick(this, [
      'onChangeStartTime',
      'onChangeEndTime',
      'onSearch'
    ])

    const tableFunProps = util.pick(this, [
      'onChangePagination',
    ])

    return (
      <div>
        <Card title="月统计数据">
          <Row style={{padding:24,backgroundColor: '#fff'}}>
            <MonthSendStatiticsSearch 
              {...searchProps}
              {...searchFunProps}
            />
            <MonthSendStatiticsTable 
              {...tableProps}
              {...tableFunProps}
            />
          </Row>
        </Card>
      </div>
    )
  }

  componentDidMount(){
    this.props.getData()
  }

  onChangeStartTime = (value) => {
    this.props.setStartTime(value)
  }

  onChangeEndTime = (value) => {
    this.props.setEndTime(value)
  }

  onSearch = () => {
    this.props.setPageNum(1)
    this.props.getData()
  }

  onChangePagination = (value) => {
    this.props.setPageNum(value)
    this.props.getData()
  }

} 

const mapStateToProps = (({ monthStatisticsReducer }) => ({ ...monthStatisticsReducer }))

const mapDispatchToProps = { ...actions }

export default connect(mapStateToProps, mapDispatchToProps)(MonthStatistics)